package com.kingbook.common.sender;

import com.alibaba.fastjson.JSONObject;
import com.kingbook.common.net.RestfulClient;
import org.springframework.beans.factory.annotation.Value;

import java.util.Map;

/**
 */
public class MsgPushUtil {

    static String msgPushUrl;

    @Value("${msg.push.text.url}")
    public void setMsgPushUrl(String url) {
        msgPushUrl = url;
    }


    /**
     * 消息个推
     *  appCode：应用标识
     *  clientId：应用在手机唯一标识
     *  phoneType：手机类型 [I|A]
     *  pushNo：推送内容编号（可为空）
     *  userId：用户id
     *  title：标题
     *  content：内容
     *  map：自定义参数集合（可为空）
     * @return
     */
    public static String pushMsg(String appCode, String clientId, String phoneType, String pushNo
            , String userId, String title, String content, Map<String,String> map){
        JSONObject body = new JSONObject();
        body.put("appCode", appCode);
        body.put("clientId", clientId);
        body.put("phoneType",phoneType );
        body.put("pushNo",pushNo );
        body.put("userId",userId );
        body.put("title",title );
        body.put("content",content );
        body.put("map",map );
        return RestfulClient.postAsJson(msgPushUrl,null,null,body.toJSONString());
    }


}
